package com.example.secondhandspringboot.configuration;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class RabbitmqConfig {

    // 交换机名称
    public static final String EXCHANGE_NAME="secondhandExchange";
    // 队列名称
    public static final String QUEUE_NAME="secondhandQueue";
    // 路由键
    public static final String ROUTING_KEY="zzl@520";

    @Bean
    DirectExchange myDirectExchange(){
        return new DirectExchange(EXCHANGE_NAME,true,false);
    }

    @Bean
    Queue myQueue(){
        return new Queue(QUEUE_NAME,true,false,false);
    }

    @Bean
    Binding myDirectBinding(){
        // 队列 -> 交换机 -> 路由键
        return BindingBuilder.bind(myQueue()).to(myDirectExchange()).with(ROUTING_KEY);
    }
}
